﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    public DateTime START_TIME;
    public DateTime END_TIME;
    public int SCHEDULE_ID;
    public int GROUP_ID;
    public int CLIENT_ID;
    public string EVENT_NOTES;
    public int RECURRENCE;
    public DateTime END_RECUR_DATE;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ViewChoice_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (ViewChoice.SelectedValue)
        {
            case "Day":
                OnCallCalendar.Days = 1;
                break;
            case "5-Day Week":
                OnCallCalendar.Days = 5;
                break;
            case "7-Day Week":
                OnCallCalendar.Days = 7;
                break;
        }
    }
    protected void MonthCalendar_SelectionChanged(object sender, EventArgs e)
    {
        OnCallCalendar.StartDate = Calendar1.SelectedDate;
    }
    protected void SelectCalendar_SelectionChanged(object sender, EventArgs e)
    {
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
    {

    }
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string clientID = TextBox1.Text;
        SqlDataSource1.SelectCommand = "SELECT * FROM data WHERE ([ ClientID]= '" + clientID + "')";
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox tb1 = (TextBox)DetailsView1.Rows[0].Cells[1].Controls[0];
        TextBox tb2 = (TextBox)DetailsView1.Rows[1].Cells[1].Controls[0];
        TextBox tb3 = (TextBox)DetailsView1.Rows[2].Cells[1].Controls[0];
        TextBox tb4 = (TextBox)DetailsView1.Rows[3].Cells[1].Controls[0];
        TextBox tb5 = (TextBox)DetailsView1.Rows[4].Cells[1].Controls[0];
        TextBox tb6 = (TextBox)DetailsView1.Rows[5].Cells[1].Controls[0];
        TextBox tb7 = (TextBox)DetailsView1.Rows[6].Cells[1].Controls[0];
        TextBox tb8 = (TextBox)DetailsView1.Rows[7].Cells[1].Controls[0];
        AddEvent(tb1.Text, tb2.Text, tb3.Text, DateTime.Parse(tb4.Text), DateTime.Parse(tb5.Text), tb6.Text, tb7.Text, tb8.Text);
    }
    protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
    {

    }
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        /*
        START_TIME = new DateTime(MonthCalendar.SelectedDate.Year,MonthCalendar.SelectedDate.Month,MonthCalendar.SelectedDate.Day,int.Parse(DropDownList1.SelectedValue),int.Parse(DropDownList2.SelectedValue),0);
        if(DropDownList3.SelectedValue == "PM")
            START_TIME = new DateTime(MonthCalendar.SelectedDate.Year,MonthCalendar.SelectedDate.Month,MonthCalendar.SelectedDate.Day,int.Parse(DropDownList1.SelectedValue)+12,int.Parse(DropDownList2.SelectedValue),0);
        else
            START_TIME = new DateTime(MonthCalendar.SelectedDate.Year,MonthCalendar.SelectedDate.Month,MonthCalendar.SelectedDate.Day,int.Parse(DropDownList1.SelectedValue),int.Parse(DropDownList2.SelectedValue),0);
        END_TIME = new DateTime(MonthCalendar.SelectedDate.Year,MonthCalendar.SelectedDate.Month,MonthCalendar.SelectedDate.Day,int.Parse(DropDownList4.SelectedValue),int.Parse(DropDownList5.SelectedValue),0);
        if (DropDownList6.SelectedValue == "PM")
            END_TIME = new DateTime(MonthCalendar.SelectedDate.Year, MonthCalendar.SelectedDate.Month, MonthCalendar.SelectedDate.Day, int.Parse(DropDownList4.SelectedValue) + 12, int.Parse(DropDownList5.SelectedValue), 0);
        else
            END_TIME = new DateTime(MonthCalendar.SelectedDate.Year, MonthCalendar.SelectedDate.Month, MonthCalendar.SelectedDate.Day, int.Parse(DropDownList4.SelectedValue), int.Parse(DropDownList5.SelectedValue), 0);

        */
    }
    protected void DetailsView1_PageIndexChanging1(object sender, DetailsViewPageEventArgs e)
    {

    }
    protected void DetailsView1_PageIndexChanging2(object sender, DetailsViewPageEventArgs e)
    {

    }

    public void AddEvent(string SID, string GID, string CID, DateTime start, DateTime end, string note, string recur, string endrecur)
    {
        SqlDataSource1.InsertCommand =
            "INSERT INTO data ([ScheduleID],[ GroupID],[ ClientID],[ StartTime],[ EndTime],[ Notes],[ Recurrence],[ EndRecurDate]) " +
            "VALUES ('" + SID + "','" + GID + "','" + CID + "','" + start + "','" + end + "','" + note + "','" + recur + "','" + endrecur + "')";
        SqlDataSource1.Insert();
    }
}
